<?php
/**
 * 接收网站POST账户信息类
 * Created by PhpStorm.
 * User: 李洋波
 * Date: 2016/8/4
 * Time: 10:28
 */

class PostAccountInfo extends  CI_Controller{
    function __construct()
    {
        parent::__construct();
        $this->load->model('api_model/tom_account_model','account');
        $this->load->model('api_model');
    }

    /**
     * 新增账户
     */
    public function AddAccount(){
        $gp=gp();
        $this->load->library('ApiVerification');
        //实例化验证类
        $Api = new ApiVerification();
        //验证token
        $tokenResult=$Api->TokenVerification($gp['access_token'],'DepositRecord');
        //通过处理
        if($tokenResult['code']=='1'){
            //允许POST键
            $allowPostKey=array('tr_id','name','email','company');
            //必须POST键
            $mustPostKey=array('tr_id','name','email','company');
            //非空键
            $notNullKey=array('tr_id','name','email');
            //验证POST 数据
            $dataResult=$Api->DataVerification($allowPostKey,$mustPostKey,$notNullKey,$gp['data']);
            //通过处理
            if($dataResult['code']=='1'){
                //tr_id 重复验证
                $tr_id=$this->account->AccountVerify($gp['data']['tr_id']);
                if($tr_id) {
                    //更新处理
                    $this->account->APIUpdate($gp['data']['tr_id'],$gp['data']);
                }else{
                    //入库处理
                    $this->account->AddAccount($gp['data']);
                }
                //返回结果
                echo json_encode($dataResult);
            }else{
                //异常抛出
                echo json_encode($dataResult);
            }
        }else{
            //异常抛出
            echo json_encode($tokenResult);
        }
    }

}